<script language="javascript" type="text/javascript">
    $(window).scroll(
    function()
    {
        scrollTop = $(window).scrollTop();
        docHeight = getDocHeight();
        winHeight = getWinHeight();
        scrolltop20 = Math.round((getDocHeight() - getWinHeight())*0.9);
        result = getDocHeight() - getWinHeight();
		
        console.log('Top Scroll: '+ scrollTop +' || Win Height: '+ winHeight +' || Doc Height: '+ docHeight+' || scrolltop20: '+scrolltop20+' || result :'+ result );
	
        if($(window).scrollTop() >= scrolltop20)
        {
            if(killScroll == false) 
            {
                killScroll = true;
				
                $('#loading').show();
                $('#loadding-text').show();			
                $('#loading').html('<img src="images/loading.gif" alt="" width="150" height="13" />');
				
                if($("li:last").data('ctype') == 'activity')
                {
                    lastPostFunc('activity');
                }
                setTimeout(function(){killScroll = false},500);	
            }
        }
    }
); 
</script>

<!-- Start of news page -->
<div data-role="page" id="activity">
    <div data-role="header">
        <h1>ปฏิทินกิจกรรม</h1>
        <a rel="external" id="link_web" href="?q=home" data-icon="back" data-iconpos="right" data-transition="flip">กลับ</a>        
    </div><!-- /header -->

    <div data-role="content">	
        <ul data-role="listview" >
            <li data-role="list-divider" id="listDivider_step">
                <a rel="external" href="?q=home">หน้าแรก</a>&nbsp;&nbsp;>>&nbsp;&nbsp;<a rel="external" href="?q=activity">กิจกรรม</a>
            </li>      
            <?php
            $count_activity = $db->num_rows('activity', 'id', 'activity_date >= "' . date('Y-m-d H:i:s') . '"');
            if($count_activity > 0)
            {
                $res = $db->select_query('SELECT id, name , activity_date FROM activity WHERE activity_date >= "' . date('Y-m-d H:i:s') . '" ORDER BY activity_date ASC, id ASC LIMIT 20');
            }
            else
            {
                $res = $db->select_query('SELECT id, name , activity_date FROM activity ORDER BY activity_date ASC, id ASC LIMIT 20');
            }

            while($arr = $db->fetch($res))
            {
                $countReply = $db->num_rows('activity_reply', 'reply_id', 'activity_id = ' . $arr['id'] . '');
                ?>      
                <li data-ctype="activity" id="activity_<?php echo $arr['id']; ?>" last_id="<?php echo $arr['id']; ?>">
                    <a rel="external" href="?q=activityDetail&activityId=<?php echo $arr['id']; ?>">
                        <img src="images/pin.png" class="ui-li-icon ">
                        <div style="font-size:20px;"><?php echo $arr['name']; ?></div>
                        <p style="margin-top:2px; font-size:12px;">วัน/เวลา : <?php echo $arr['activity_date']; ?></p>
                        <span class="ui-li-count ui-btn-up-c ui-btn-corner-all"><?php echo $countReply; ?></span>
                    </a>
                </li>    
                <?php
            }
            ?>
        </ul>
        <div id="loadding-text" style="clear:both;">&nbsp;&nbsp;</div>       
        <div id="loading" align="center">&nbsp;</div>       
    </div><!-- /content -->

    <div data-role="footer" >
        <h4>Version 1.0 Beta</h4>
        <a id="link_web" href="http://www.mocyc.com" data-icon="refresh" data-iconpos="right" class="ui-btn-right">แบบปกติ</a>
    </div><!-- /footer -->
</div><!-- /page -->